|
|
 |
|
 |
|
|
version. Because of this driver dependence, it is very important for applications to query the driver for the correct size of the DEVMODE structure before allocating a buffer for it. |
|
|
|
 |
|
 |
|
|
To make changes to print settings that are local to an application, an application should follow these steps: |
|
|
|
 |
|
 |
|
|
1. Get the number of bytes required for the full DEVMODE structure by calling DocumentProperties and specifying zero in the fMode parameter. |
|
|
|
 |
|
 |
|
|
2. Allocate memory for the full DEVMODE structure. |
|
|
|
 |
|
 |
|
|
3. Get the current printer settings by calling DocumentProperties. Pass a pointer to the DEVMODE structure allocated in Step 2 as the pDevModeOutput parameter and specify the DM_OUT_BUFFER value. |
|
|
|
 |
|
 |
|
|
4. Modify the appropriate members of the returned DEVMODE structure and indicate which members were changed by setting the corresponding bits in the dmFields member of the DEVMODE. |
|
|
|
 |
|
 |
|
|
5. Call DocumentProperties and pass the modified DEVMODE structure back as both the pDevModeInput and pDevModeOutput parameters and specify both the DM_IN_BUFFER and DM_OUT_BUFFER values (which are combined using the OR operator). |
|
|
|
|
|
|
|
|
As you can see, even though the C function declaration describes the pDevModeInput and pDevModeOutput parameters as type PDEVMODE (pointer to a DEVMODE structure), a close reading of the function description makes it clear that this is not the whole story. In fact, these parameters are pointers to memory buffers that have a DEVMODE structure at the start of the buffer, followed by additional device-specific data. From the C perspective, describing these parameters as the PDEVMODE data type is entirely correctthe parameter is, in fact, a pointer to a DEVMODE structure. It just happens to have additional data after the structure. |
|
|
|
|
|
|
|
|
From the Visual Basic perspective, things are a bit more complicated. If you declare the parameter type as a DEVMODE structure, you won't be including the additional data. Some printer drivers don't use private data in the DEVMODE structure. These printers will work just fine with the code in the puzzle. But those drivers that do use the private data will attempt to access memory that is outside of the structure. In some cases, this will have no effect or will just lead to some strange printer settings. In other cases, you may get a memory exception, your |
|
|
|
|
|